﻿var isFirst = true;
var num = 0;
var conclData = []; //保存评价结果
var interNum = 0; //记录评价项个数
var iID; //循环暂停标记
//进入界面时初始化
function load() {
    getEvalNameList();
}
//获得评价项名称列表并初始化
function getEvalNameList() {
    var Tvalue = $("#ddl_scheme").val(); //方案id
    $.ajax({
        url: 'ajax_SingleWellAssess.ashx',
        type: 'get',
        dataType: 'xml', //这里可以不写，但千万别写text或者html!!! 
        data: { task: "getEval_NAME", id: Tvalue },
        timeout: 2000,
        cache: false,
        error: function (xml) {
            alert('数据有错误' + xml);
        },
        success: function (xml) {
            var data1 = [];
            $(xml).find("evatables").children().each(function () {
                var EVAL_NAME = $(this).children("EVAL_NAME").text();
                var EVAL_ID = $(this).children("EVAL_ID").text();
                data1.push([EVAL_ID, EVAL_NAME, ]);
            });
            createTable(data1);
            //            createLine(data1);

        }
    });
}
//获得评价结果集
function getEvalConclList() {
    var wellid = $("#txt_jh").val(); //井号
    var rq = $("#txt_jcrq").val(); //$("#txt_jcrq").currentText; //采集日期
    var Tvalue = $("#ddl_scheme").val(); //方案id
    $.ajax({
        url: 'ajax_SingleWellAssess.ashx',
        type: 'get',
        dataType: 'xml', //这里可以不写，但千万别写text或者html!!! 
        data: { task: "getEvalMODEL", wellid: wellid, jcrq: rq, schemeid: Tvalue },
        timeout: 2000,
        cache: false,
        error: function (xml) {
            alert('数据有错误' + xml);
        },
        success: function (xml) {
            var data1 = [];
            $(xml).find("evatables").children().each(function () {
                var EVAL_ID = $(this).children("EVAL_ID").text(); //评价项ID
                var EVAL_NAME = $(this).children("EVAL_NAME").text(); //评价项名称
                var EVAL_VALUE = $(this).children("EVAL_VALUE").text(); //分数
                var EVAL_DESC = $(this).children("EVAL_DESC").text(); //建议
                data1.push([EVAL_ID, EVAL_NAME, EVAL_VALUE, EVAL_DESC]);
                conclData.push([EVAL_ID, EVAL_NAME, EVAL_VALUE, EVAL_DESC]);
            });
            start();
        } //success
    });
}
//初始化评价结果列表
function createTable(data) {
    var t = document.getElementById('evalTable');
    $("#evalTable tbody").html("");
    for (var i = data.length - 1; i > -1; i--) {
        //初始化建议和分数部分
        var tr = t.insertRow(0);
        var c1 = tr.insertCell(0);
        var c2 = tr.insertCell(1);
        c2.setAttribute('width', '20%');
        c1.innerHTML = '<div align="right">' + data[i][1].toString() + '</div>' + '<div align="right">' + '建议：' + '</div>' + '<div  align="right" id=' + data[i][0].toString() + 'EVAL_DESC' + '>' + '</div>';
        c2.innerHTML = '<div align="right" id=' + data[i][0].toString() + 'EVAL_VALUE' + '>' + '<img src="images\\Singleassess\\100.png">' + '</div>';
        tr.setAttribute('height', '110px');
    }
    tr.setAttribute('border', '1');

}
//生成进度条下面的评价项名称列表
function createLine(data) {
    var tr = document.getElementById('tr_line_evalname');
    $("#tr_line_evalname").html("");
    for (var i = 0; i < data.length; i++) {
        var c1 = tr.insertCell(i);
        c1.innerHTML = '<td align="center" class="STYLE14">' + data[i][1].toString() + '</td>';
    }

}

//初始化分数和建议
function initioalValueDesc() {
    if (interNum == conclData.length - 2) {
        //得出最后一个评价项的建议和分数
        var div_desc = document.getElementById(conclData[interNum][0].toString() + "EVAL_DESC");
        div_desc.innerHTML = conclData[interNum][3].toString();
        var div_value = document.getElementById(conclData[interNum][0].toString() + "EVAL_VALUE");
        div_value.innerHTML = '<div align="right "id=' + conclData[interNum][0].toString() + 'EVAL_VALUE' + '>' + '<img src="images\\Singleassess\\' + conclData[interNum][2].toString() + '.png ' + '">' + '</div>';
        //得出总建议和总分
        var div_zongfenValue = document.getElementById("img_zongfen");
        div_zongfenValue.innerHTML = '<div id="img_zongfen">' + '<img src="images\\Singleassess\\' + conclData[interNum + 1][2].toString() + '.png ' + '">' + '</div>';
        //得出结果分布图
        var div_zongtuValue = document.getElementById("img_zongtu");
        div_zongtuValue.innerHTML = '<div id="img_zongtu">' + '<img src="images\\Singleassess\\zongtu.jpg" width="227" height="216">' + '</div>';
        //清除进度条上正在检测项名称
        var div_analyNow = document.getElementById("div_analyNow");
        div_analyNow.innerHTML = '<div id="div_analyNow" align="left" style="display: inherit"  class="STYLE14">' + '&nbsp;&nbsp;&nbsp;综合得分：' + conclData[interNum + 1][2].toString() + '分' + '</div>';
        clearInterval(iID);
    }
    else {
        //得出[interNum]处的评价项建议
        var div_desc = document.getElementById(conclData[interNum][0].toString() + "EVAL_DESC");
        div_desc.innerHTML = conclData[interNum][3].toString();
        //得出[interNum]处的评价项得分
        var div_value = document.getElementById(conclData[interNum][0].toString() + "EVAL_VALUE");
        div_value.innerHTML = '<div id=' + conclData[interNum][0].toString() + 'EVAL_VALUE' + '>' + '<img src="images\\Singleassess\\' + conclData[interNum][2].toString() + '.png ' + '">' + '</div>';
        //让[interNum+1]处的评价项分数图片转动等待
        var div_value1 = document.getElementById(conclData[interNum + 1][0].toString() + "EVAL_VALUE");
        div_value1.innerHTML = '<div id=' + conclData[interNum + 1][0].toString() + 'EVAL_VALUE' + '>' + '<img src="images\\Singleassess\\100.gif">' + '</div>';
        //生成进度条上正在检测项名称
        var div_analyNow = document.getElementById("div_analyNow");
        div_analyNow.innerHTML = '<div id="div_analyNow" align="left" style="display: inherit"  class="STYLE14">' + '&nbsp;&nbsp;&nbsp;正在检测项：' + conclData[interNum + 1][1].toString() + '</div>';
        interNum++;
    }
}

//开始调用时钟函数和进度条 
function start() {
    interNum = 0;
    //初始化第一个评价项图片
    var div_value1 = document.getElementById(conclData[interNum][0].toString() + "EVAL_VALUE");
    div_value1.innerHTML = '<div id=' + conclData[interNum][0].toString() + 'EVAL_VALUE' + '>' + '<img src="images\\Singleassess\\100.gif">' + '</div>';
    //初始化总分图片
    var div_zongfenValue = document.getElementById("img_zongfen");
    div_zongfenValue.innerHTML = '<div id="img_zongfen">' + '<img src="images\\Singleassess\\100.gif">' + '</div>';
    //生成进度条上正在检测项名称
    var div_analyNow = document.getElementById("div_analyNow");
    div_analyNow.innerHTML = '<div id="div_analyNow" align="left" style="display: inherit"  class="STYLE14">' + '&nbsp;&nbsp;&nbsp;正在检测项：' + conclData[0][1].toString() + '</div>';

    var columNum = conclData.length;
    var time = 12000 / (columNum - 1);
    iID = setInterval(initioalValueDesc, time);
    $('#progress1').anim_progressbar(); //进度条启动
}

//触发页面元素事件
var fun;
$(document).ready(fun = function () {
    //进入页面初始化
    load();
    //获得评价项名称列表并初始化
    $('#ddl_scheme').change(function () {
        //初始化总分
        var div_zongfenValue = document.getElementById("img_zongfen");
        div_zongfenValue.innerHTML = '<div id="img_zongfen">' + '<img src="images\\Singleassess\\100.png">' + '</div>';
        //清空评价结果集数组
        conclData = [];
        //清除进度条上正在检测项名称
        var div_analyNow = document.getElementById("div_analyNow");
        div_analyNow.innerHTML = "";
        getEvalNameList();
    });
    //开始检测按钮
    $('#btn_start').click(function () {
        getEvalConclList();

    }); //开始检测按钮结束
    //返回主页面
    $('#backMain').click(function () {
        parent.openSonPage("analysisMain.aspx");
    });

    //进度条js
    jQuery.fn.anim_progressbar = function (aOptions) {
        // def values   
        var iCms = 200;
        var iMms = 30 * iCms;
        var iHms = 3600 * iCms;
        var iDms = 12 * 3600 * iCms;

        // def options
        var aDefOpts = {
            start: new Date(), // now
            finish: new Date().setTime(new Date().getTime() + 60 * iCms), // now + 60 sec
            interval: 100
        }
        var aOpts = jQuery.extend(aDefOpts, aOptions);
        var vPb = this;

        // each progress bar
        return this.each(
                 function () {
                     $("#img_zongfen").attr("src", "images/Singleassess/100.gif");
                     var iDuration = aOpts.finish - aOpts.start;
                     // calling original progressbar
                     $(vPb).children('.pbar').progressbar();

                     // looping process
                     var vInterval = setInterval(
                         function () {
                             var iLeftMs = aOpts.finish - new Date(); // left time in MS
                             var iElapsedMs = new Date() - aOpts.start, // elapsed time in MS
                                 iDays = parseInt(iLeftMs / iDms), // elapsed days
                                 iHours = parseInt((iLeftMs - (iDays * iDms)) / iHms), // elapsed hours
                                 iMin = parseInt((iLeftMs - (iDays * iDms) - (iHours * iHms)) / iMms), // elapsed minutes
                                 iSec = parseInt((iLeftMs - (iDays * iDms) - (iMin * iMms) - (iHours * iHms)) / iCms), // elapsed seconds
                                 iPerc = (iElapsedMs > 0) ? iElapsedMs / iDuration * 100 : 0; // percentages
                             $(vPb).children('.pbar').children('.ui-progressbar-value').css('width', iPerc + '%');
                             // in case of Finish
                         }, aOpts.interval
                     );
                 }
             ); //function ()
    }

})

